package org.argetr.resim.ui.rcp.rcp;


import org.argetr.resim.ShapesEditor;
import org.argetr.resim.proc.tools.ShapeDiagramRunner;
import org.argetr.resim.ui.model.ShapesDiagram;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;



public class RunProjectAction extends Action{
	public final static String RUN_ACTION_ID="PROJECT_RUN_ACTION";

	private IWorkbenchWindow _workbenchWindow;
	
	public RunProjectAction(IWorkbenchWindow window,String displayName) {
		setId(RUN_ACTION_ID);
		setText(displayName);
		_workbenchWindow = window;
	}
	
	public void run() {
		try
		{		
			IEditorPart lEditorPart = _workbenchWindow.getActivePage().getActiveEditor();
			ShapesDiagram lShapesDiagram = ((ShapesEditor)lEditorPart).getModel();
			ShapeDiagramRunner.setShapesDiagram(lShapesDiagram);
			ShapeDiagramRunner.run();
			/*if(lEditorPart instanceof ShapesEditor)
			{				
				ShapesDiagram lShapesDiagram = ((ShapesEditor)lEditorPart).getModel();
				List<Shape> lShape = lShapesDiagram.getChildren();
				for(Shape tempShape : lShape)
				{
					if(tempShape instanceof ComponentItem)
					{
						ComponentItem compItem = (ComponentItem)tempShape;
						if(compItem.isInitialProcessor())
						{							
							compItem.process();
						}
					}					
				}
			}*/
			/*
			if(lEditorPart instanceof DiagramEditPart)
			{
				ShapesDiagram lShapesDiagram = ((DiagramEditPart)lEditorPart).getCastedModel();
				
				System.out.println("# of Shapes = "+lShapesDiagram.getChildren().size());
			}*/
		}
		catch(Exception exp)
		{
			System.err.println(exp.getMessage());
		}
	}
}
